package com.ruoyi.web.controller.mes;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.uuid.UUID;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.domain.mes.MesCustom;
import com.ruoyi.web.service.IMesCustomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 客户信息Controller
 *
 * @author levicash
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/mes/custom")
public class MesCustomController extends BaseController {
    @Autowired
    private IMesCustomService mesCustomService;

    /**
     * 查询客户信息列表
     */

    @GetMapping("/list")
    public TableDataInfo list(MesCustom mesCustom) {
        startPage();
        List<MesCustom> list = mesCustomService.selectMesCustomList(mesCustom);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('mes:custom:export')")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesCustom mesCustom) {
        List<MesCustom> list = mesCustomService.selectMesCustomList(mesCustom);
        ExcelUtil<MesCustom> util = new ExcelUtil<MesCustom>(MesCustom.class);
        util.exportExcel(response, list, "客户信息数据");
    }

    /**
     * 导入客户信息数据
     */
    @Log(title = "客户信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<MesCustom> util = new ExcelUtil<MesCustom>(MesCustom.class);
        List<MesCustom> mesCustomList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = mesCustomService.importCustom(mesCustomList, updateSupport, operName);
        return success(message);
    }

    /**
     * 下载客户信息模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<MesCustom> util = new ExcelUtil<MesCustom>(MesCustom.class);
        util.importTemplateExcel(response, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mesCustomService.selectMesCustomById(id));
    }

    /**
     * 新增客户信息
     */

    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesCustom mesCustom) {
        return toAjax(mesCustomService.insertMesCustom(mesCustom));
    }

    /**
     * 修改客户信息
     */

    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesCustom mesCustom) {
        return toAjax(mesCustomService.updateMesCustom(mesCustom));
    }

    /**
     * 删除客户信息
     */

    @Log(title = "客户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mesCustomService.deleteMesCustomByIds(ids));
    }

    /**
     * 状态修改
     */

    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody MesCustom mesCustom) {
        return toAjax(mesCustomService.updateMesCustomStatus(mesCustom));
    }

}
